package com.shop.cereshop.app.service.pet.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shop.cereshop.app.dao.pet.CerePetInfoDAO;
import com.shop.cereshop.app.page.pet.PetInfoVO;
import com.shop.cereshop.app.service.pet.CerePetInfoService;
import com.shop.cereshop.commons.domain.buyer.CereBuyerUser;
import com.shop.cereshop.commons.domain.pet.CerePetInfo;
import com.shop.cereshop.commons.exception.CoBusinessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Administrator
 * @description 针对表【cere_pet_info(宠物信息表)】的数据库操作Service实现
 * @createDate 2025-08-08 16:46:02
 */
@Service
public class CerePetInfoServiceImpl extends ServiceImpl<CerePetInfoDAO, CerePetInfo> implements CerePetInfoService {

    @Resource
    private CerePetInfoDAO cerePetInfoDAO;

    @Override
    public List<PetInfoVO> getPetInfo(Long buyerUserId) {
        List<PetInfoVO> petInfos = cerePetInfoDAO.getPetInfo(buyerUserId);
        for (PetInfoVO petInfoVO : petInfos) {
            petInfoVO.setAge(petInfoVO.getAge());
        }
        return petInfos;
    }

    @Override
    @Transactional(isolation= Isolation.DEFAULT,propagation= Propagation.REQUIRED,rollbackFor = {CoBusinessException.class, Exception.class})
    public boolean updatePetInfo(PetInfoVO petInfoVO, CereBuyerUser user) {
        petInfoVO.setBuyerUserId(user.getBuyerUserId());
        return saveOrUpdate(petInfoVO);
    }

    @Override
    public PetInfoVO getDetailById(Long petId) {
        //根据宠物id查询宠物信息详情
        PetInfoVO petInfoVO = cerePetInfoDAO.getDetailById(petId);
        petInfoVO.setAge(petInfoVO.getAge());
        return petInfoVO;
    }
}
